﻿
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="page-container">
    <div class="page-content">

        <div class="titlePanel">
            <div class="title-search">
                <table>
                    <tr>
                        <td style="padding-left: 2px;">
                            <input id="txt_keyword" type="text" class="form-control" placeholder="名称" style="width: 200px;" />
                        </td>
                        <td style="padding-left: 5px;">
                            <a id="btn_search" class="btn btn-primary btn-sm"><i class="fa fa-search"></i>&nbsp;查询</a>
                        </td>
                    </tr>
                </table>
            </div>
            <div class="toolbar">
                <div class="btn-group">
                    <a id="replace" class="btn btn-default" onclick="reload();"><i class="fa fa-refresh"></i>&nbsp;刷新</a>
                    <a id="add" authorize="yes" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增</a>
                    <a id="edit" authorize="yes" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑</a>
                    <a id="delete" authorize="yes" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
                    <a id="modulebutton" authorize="yes" class="btn btn-default" onclick="btn_modulebutton()"><i class="fa fa-key"></i>&nbsp;按钮管理</a>
                </div>
                <script>$('.toolbar').authorizeButton();</script>
            </div>
        </div>
        <div class="gridPanel">
            <table id="gridTable"></table>
        </div>
    </div>
</div>
<script>
    $(function () {
        gridTable();
    })
    function gridTable() {
        var $gridTable = $("#gridTable");
        $gridTable.jqGridEx({
            treeGrid: true,
            height: $(window).height() - 96,
            ExpandColumn: "url",
            treeGridModel: "adjacency",
            url: "/SystemManage/Module/GetTreeGridJson",
            colModel: [
                { label: "主键", name: "id", hidden: true, key: true },
                { label: '名称', name: 'text', width: 200, align: 'left', sortable: false },
                { label: '连接', name: 'url', width: 260, align: 'left', sortable: false },
                {
                    label: '目标', name: 'targetType', width: 80, align: 'center', sortable: false,
                    formatter: function (cellvalue) {
                        if (cellvalue == "expand") {
                            return "无页面";
                        } else if (cellvalue == "iframe-tab") {
                            return "框架页";
                        } else if (cellvalue == "open") {
                            return "弹出页";
                        } else if (cellvalue == "blank") {
                            return "新窗口";
                        }
                    }
                },
                {
                    label: "菜单", name: "IsMenu", width: 60, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    label: "展开", name: "isOpen", width: 60, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    label: "公共", name: "IsPublic", width: 60, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        return cellvalue == true ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                {
                    label: "有效", name: "EnabledMark", width: 60, align: "center", sortable: false,
                    formatter: function (cellvalue) {
                        return cellvalue == 1 ? "<i class=\"fa fa-toggle-on\"></i>" : "<i class=\"fa fa-toggle-off\"></i>";
                    }
                },
                { label: '介绍', name: 'Description', width: 300, align: 'left', sortable: false }
            ]
        });
        
        $("#btn_search").click(function () {
            $gridTable.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function btn_add() {
        $.fn.modalOpen({
            id: "Form",
            title: "新增菜单",
            url: "/SystemManage/Module/Form",
            width: "700px",
            height: "440px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (checkedRow(keyValue)) {
            $.fn.modalOpen({
                id: "Form",
                title: "修改菜单",
                url: "/SystemManage/Module/Form?keyValue=" + keyValue,
                width: "700px",
                height: "440px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        }
    }
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (keyValue) {
            $.fn.deleteForm({
                url: "/SystemManage/Module/DeleteForm",
                param: { keyValue: keyValue },
                success: function () {
                    $("#gridTable").resetSelection().trigger("reloadGrid");
                }
            })
        } else {
            $.fn.modalMsg('请选择需要删除的数据项！', "warning");
        }

    }
    function btn_details() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (keyValue) {
            $.fn.modalOpen({
                id: "Details",
                title: "查看菜单",
                url: "/SystemManage/Module/Details?keyValue=" + keyValue,
                width: "700px",
                height: "490px",
                btn: null,
            });
        } else {
            $.fn.modalMsg('请选择需要查看的数据项！', "warning");
        }

    }
    function btn_modulebutton() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (keyValue) {
            $.fn.modalOpen({
                id: "modulebutton",
                title: "系统按钮",
                url: "/SystemManage/ModuleButton/Index?moduleId=" + keyValue,
                width: "870px",
                height: "600px",
                btn: null,
            });
        } else {
            $.fn.modalMsg('请选择需要管理的数据项！', "warning");
        }

    }
</script>
